package com.example.udp2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;


public class UdpClient2 {
  public static void main(String[] args) throws IOException {
      DatagramSocket ds = new DatagramSocket(5556);

      String msg = "ABCDabcd";

      byte[] bytes = msg.getBytes();
      // 打包发送
      for (int i = 0; i < 10; i++) {
          DatagramPacket dp =
                  new DatagramPacket(bytes, bytes.length, new InetSocketAddress("localhost", 8090));
          ds.send(dp);
          byte[] buff = new byte[1024];
          DatagramPacket dp2 = new DatagramPacket(buff, 1024);
          ds.receive(dp2);
          byte[] bytes1 = dp2.getData();
          int len = dp2.getLength();
          System.out.println("客户端收到的消息是"+new String(bytes1,0,len));
      }
  }
  }

